package com.nulldev.util.web.flexibleKit.scfk.io.keepalive;

import com.nulldev.util.web.flexibleKit.scfk.protocols.PreferredProtocol;

public class ProtocolKeepAlive {

	public static class KeepAliveParams {
		public final int maximumReuse;
		public final int maximumDuration;

		protected KeepAliveParams(final int maximumReuse, final int maximumDuration) {
			this.maximumDuration = maximumDuration;
			this.maximumReuse = maximumReuse;
		}
	}

	public static final KeepAliveParams UNSUPPORTED = new KeepAliveParams(-1, -1);
	public static final int MAXIMUM_GLOBAL_USE_COUNT = 100;

	public static KeepAliveParams getParamsFor(final PreferredProtocol protocol) {
		switch (protocol) {
			case HTTP_0_9:
			case HTTP_1_0:
			case HTTP_2_0:
			case HTTP_3_0:
			case STTP_0_1:
			case GEMINI:
			case GOPHER:
				return UNSUPPORTED;
			case HTTP_1_1:
				return new KeepAliveParams(MAXIMUM_GLOBAL_USE_COUNT, 300);
			case STTP_0_2:
				return new KeepAliveParams(MAXIMUM_GLOBAL_USE_COUNT, 60);
			default:
				return UNSUPPORTED;
		}
	}
}
